package com.example.service.impl;

import com.example.domain.CultureShop;
import com.example.mapper.CultureShopDao;
import com.example.service.CultureShopService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (CultureShop)表服务实现类
 *
 * @author makejava
 * @since 2025-03-29 17:48:39
 */
@Service("cultureShopService")
public class CultureShopServiceImpl implements CultureShopService {
    @Resource
    private CultureShopDao cultureShopDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CultureShop queryById(Integer id) {
        return this.cultureShopDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param cultureShop 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<CultureShop> queryByPage(CultureShop cultureShop, PageRequest pageRequest) {
        long total = this.cultureShopDao.count(cultureShop);
        return new PageImpl<>(this.cultureShopDao.queryAllByLimit(cultureShop, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param cultureShop 实例对象
     * @return 实例对象
     */
    @Override
    public CultureShop insert(CultureShop cultureShop) {
        this.cultureShopDao.insert(cultureShop);
        return cultureShop;
    }

    /**
     * 修改数据
     *
     * @param cultureShop 实例对象
     * @return 实例对象
     */
    @Override
    public CultureShop update(CultureShop cultureShop) {
        this.cultureShopDao.update(cultureShop);
        return this.queryById(cultureShop.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.cultureShopDao.deleteById(id) > 0;
    }
}
